// VTKCompassStudio.h
#ifndef VTKCOMPASSSTUDIO_H
#define VTKCOMPASSSTUDIO_H

#include <QObject>
#include <QColor>

// VTK 相关头文件
#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkDiskSource.h>
#include <vtkVectorText.h>
#include <vtkPolyDataMapper.h>
#include <vtkLineSource.h>
#include <vtkRenderer.h>

class VTKCompassStudio : public QObject
{
    Q_OBJECT

  public:
    explicit VTKCompassStudio(QObject* parent = nullptr);
    ~VTKCompassStudio();

    // 基本控制
    void setVisible(bool visible);
    bool isVisible() const
    {
        return m_visible;
    }

    void setRenderer(vtkRenderer* renderer);
    vtkRenderer* getRenderer() const
    {
        return m_renderer;
    }

    // 位置和大小控制
    void setPosition(double x, double y, double z);
    void getPosition(double& x, double& y, double& z) const;
    void setScale(double scale);
    double getScale() const
    {
        return m_scale;
    }

    // 颜色控制
    void setDiskColor(double r, double g, double b);
    void setDiskColor(const QColor& color);
    QColor getDiskColor() const;

    void setTextAndLineColor(double r, double g, double b);  // 统一设置文字和线条颜色
    void setTextAndLineColor(const QColor& color);
    QColor getTextAndLineColor() const;

    // 透明度控制
    void setDiskOpacity(double opacity);
    double getDiskOpacity() const;

    void setTextAndLineOpacity(double opacity);  // 统一设置文字和线条透明度
    double getTextAndLineOpacity() const;

    // 圆环参数控制
    void setDiskRadius(double innerRadius, double outerRadius);
    void getDiskRadius(double& innerRadius, double& outerRadius) const;

    void setDiskResolution(int radialResolution, int circumferentialResolution);
    void getDiskResolution(int& radialResolution, int& circumferentialResolution) const;

    // 线宽控制
    void setLineWidth(double width);
    double getLineWidth() const;

    // 方向标签控制
    void setDirectionLabelsVisible(bool visible);
    bool areDirectionLabelsVisible() const;

    void setDiagonalLinesVisible(bool visible);
    bool areDiagonalLinesVisible() const;

    // 更新所有属性
    void updateAllProperties();

  private:
    void createCompass();
    void createDirectionText(const char* text, vtkSmartPointer<vtkActor>& textActor, double x, double y, double z);
    void createDiagonalLine(vtkSmartPointer<vtkActor>& lineActor, double angleDegrees);
    void updateTextPositions();
    void updateLinePositions();
    void updateColors();
    void updateOpacities();
    void updateTextSize();

  private:
    vtkRenderer* m_renderer;

    // 罗盘组件
    vtkSmartPointer<vtkDiskSource> m_diskSource;
    vtkSmartPointer<vtkActor> m_diskActor;

    // 方向文字
    vtkSmartPointer<vtkActor> m_northText;
    vtkSmartPointer<vtkActor> m_southText;
    vtkSmartPointer<vtkActor> m_eastText;
    vtkSmartPointer<vtkActor> m_westText;

    // 刻度线
    vtkSmartPointer<vtkActor> m_neLine;
    vtkSmartPointer<vtkActor> m_seLine;
    vtkSmartPointer<vtkActor> m_swLine;
    vtkSmartPointer<vtkActor> m_nwLine;

    // 状态
    bool m_visible;
    bool m_directionLabelsVisible;
    bool m_diagonalLinesVisible;

    // 属性
    double m_position[3];
    double m_scale;

    double m_diskColor[3];
    double m_textAndLineColor[3];  // 统一文字和线条颜色

    double m_diskOpacity;
    double m_textAndLineOpacity;  // 统一文字和线条透明度

    double m_innerRadius;
    double m_outerRadius;
    int m_radialResolution;
    int m_circumferentialResolution;

    double m_lineWidth;
};

#endif  // VTKCOMPASSSTUDIO_H